<?php

namespace Modules\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AdminUserRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
    	$id=$this->route ('adminuser');
        return [
            'name'=>'required|min:5|unique:admins,name,'.$id,
			'nickname'=>'required|min:5,unique:admins,nickname,'.$id,
			'password'=>'nullable|between:6,20'
        ];
    }

    public function messages ()
	{
		return [
			'name.required'=>'用户名不能为空',
			'nickname.required'=>'用户昵称不能为空',
			'password.required'=>'密码不能为空',
			'name.min'=>'用户名长度至少为5位',
			'nickname.min'=>'用户昵称长度至少为5位',
			'name.unique'=>'用户名已存在',
			'nickname.unique'=>'用户昵称已存在',
			'password.between'=>'用户密码必须在6-20位之间'
		];
	}

	/**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }
}
